<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var a = 5
    function outer() {
      var a = 6;
      console.log(a);//6
      function inner() {
        var a = 7;
        console.log(a);//7
        a = 8;
        console.log(a);//8
      }
      inner();
      console.log(a);//6
    }
    outer()
    console.log(a);//5


    //函数提升（function）
    var value = 1;
    //通过var定义的不行
    //fn1()

    bar()
    //词法作用域：指函数在定义（或声明）他们的作用域里运行
    //而不是在执行（或调用）他们的作用域里运行
    function fag() {
      console.log(value);
    }
    function bar() {
      var value = 2
      fag();
    }
    bar()//1

    var fn1 = function () {
      console.log(666);
    }

    fn1();
  </script>
</body>

</html>